var cleanestCities = ["Cheyenne", "Santa Fe", "Tucson"];
var numElements = cleanestCities.lenght;
var matchFound = false;
for (var i = 0; i < numElements; i++) {
if (cityToCheck == cleanestCities[i]) {
matchFound = true;
alert("It's one of the cleanest cities");
break;
}
}
if (matchFound == false {
alert("It's not on the list");
}
While Loops:
var i = 0;
while (i <= 3) {
alert(i);
i++;
}
The difference between a while loop and do while is that the statements in the code block come before the condition.
That means the statements are run once whether or not the condition is met.